import React from 'react';
import ReactDOM from 'react-dom/client';
import {BrowserRouter as Router, Route, Routes} from 'react-router-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import {adminRoutes, mainRoutes} from "./routes";
import PageNotFound from "./pages/PageNotFound";
import {Provider} from 'react-redux';
import store from './store';


const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
    <Provider store={store}>
        <React.StrictMode>
            <Router>
                <Routes>
                    {/* 主路由 */}
                    <Route path="/" element={<div>首页</div>}/>

                    {/* 管理员路由 - 使用嵌套路由 */}
                    <Route path="/admin/*" element={<App/>}>
                        {adminRoutes.map((route, index) => (
                            <Route
                                key={index}
                                path={route.path.replace('/admin', '')}
                                element={<route.component/>}
                            />
                        ))}
                    </Route>

                    {/* 主要路由 */}
                    {mainRoutes.map((route, index) => (
                        <Route
                            key={index}
                            path={route.path}
                            element={<route.component/>}
                        />
                    ))}

                    {/*404页面*/}
                    <Route path="*" element={<PageNotFound/>}/>
                </Routes>
            </Router>

        </React.StrictMode>
    </Provider>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
